<div class="page-header">
    <h1>
        Form Transfer Poin
        <small>
            <i class="icon-double-angle-right"></i>
            Transfer Poin antar Member/Mitra
        </small>
    </h1>
</div>

<?php

if ($this->errmsg) {
    ?>
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-remove"></i>
            Error <br>
        </strong>

        <?php echo $this->errmsg; ?>
        <br />
    </div>
    <?php
}

if ($this->msg) {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-ok"></i>            
        </strong>

        <?php echo $this->msg; ?>
        <br />
    </div>
    <?php
}

if (!$this->msg) {
    ?>

    <div class="row">
        <div class="col-xs-11">
            <form id="formWD" class="form-horizontal" role="form" action="" method="post" onsubmit="return validate()">
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="acc_num"> Dari Nomor Akun </label>

                    <div class="col-sm-9">                        
                        <input readonly type="text" id="acc_num" name="acc_num" placeholder="Nomor Akun" value="<?php echo (isset($this->data["acc_num"])) ? $this->data["acc_num"] : $this->acc_num; ?>" class="col-xs-10 col-sm-5" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="balance2">Saldo</label>
                    <div class="col-sm-9">
                        <input readonly type="text" id="balance2" name="balance2" placeholder="Saldo" value="<?php echo (isset($this->data["balance2"])) ? $this->data["balance2"] : $this->amount2; ?>" class="col-xs-10 col-sm-5" />
                        <input type="hidden" name="balance" value="<?php echo (isset($this->data["balance"])) ? $this->data["balance"] : $this->amount; ?>" id="balance">
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="transfer"> Jumlah Transfer </label>

                <div class="col-sm-9">
                    <input type="text" id="transfer" name="transfer" placeholder="Cth: 1500000 (Tanpa titik/koma)" class="col-xs-10 col-sm-5" value="<?php echo (isset($this->data["transfer"])) ? $this->data["transfer"] : $this->transfer; ?>" required onkeypress='return validateNumber(event)' />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="min_saldo"> Minimum Saldo </label>

                <div class="col-sm-9">
                    <input type="text" id="min_saldo2" name="min_saldo2" class="col-xs-10 col-sm-5" value="<?php echo (isset($this->data["min_saldo2"])) ? $this->data["min_saldo2"] : number_format($this->minbalance); ?>" readonly />
                    <input type="hidden" id="min_saldo" name="min_saldo" value="<?php echo (isset($this->data["min_saldo"])) ? $this->data["min_saldo"] : $this->minbalance; ?>" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="to_account"> Ke Nomor Akun </label>

                <div class="col-sm-9">
                    <input type="text" id="to_account" name="to_account" placeholder="Akun Tujuan" class="col-xs-10 col-sm-5" value="<?php echo (isset($this->data["to_account"])) ? $this->data["to_account"] : ""; ?>" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="notes"> Catatan </label>

                <div class="col-sm-9">
                    <input type="text" id="notes" name="notes" placeholder="Catatan" class="col-xs-10 col-sm-5" value="<?php echo (isset($this->data["notes"])) ? $this->data["notes"] : ""; ?>" />
                </div>
            </div>

            <div class="clearfix form-actions">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-success" type="submit">
                        <i class="icon-ok bigger-110"></i>
                        Submit
                    </button>

                    &nbsp; &nbsp; &nbsp;
                    <button class="btn" type="reset">
                        <i class="icon-undo bigger-110"></i>
                        Reset
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<script>


    function validateNumber(evt) {

        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

    function validate() {

        var msg = "";

        if ($('#acc_num').val() == "")
            msg = msg + "* Nomor Akun harus dipilih\n";

        if ($('#transfer').val() == "")
            msg = msg + "* Jumlah Penarikan harus diisi\n";

        if ((eval($('#balance').val()) - (eval($('#transfer').val()))) < eval($('#min_saldo').val()) || eval($('#balance').val()) < eval($('#min_saldo').val())){
            
            msg = msg + "* Minimum Saldo tidak mencukupi\n";
        }

        if ((eval($('#transfer').val()) + eval($('#biaya').val())) > eval($('#balance').val()))
            msg = msg + "* Jumlah Transfer + Biaya lebih besar dari saldo\n";


        if (msg == "")
            return true;
        else {
            //alert("Data tidak lengkap:\n\n" + msg);
            //$.messager.alert("Data tidak lengkap:\n\n" + msg);
            bootbox.dialog({
                    message: "<span class='bigger-110'>"+msg+"</span>",
                    buttons:
                    {
                            "button" :
                             {
                                    "label" : "<i class='icon-ok'></i> Ok",
                                    "className" : "btn-sm btn-primary",
                                    //"callback": function() {
                                            //Example.show("great success");
                                    //}
                            }
                    }
            });
            return false;
        }
    }


</script>

<?php } ?>